<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<style>
    table tr th, table tr td {
        border-color: #000000;
        text-align: center;
        vertical-align: middle;
        font-size: 16px;
        line-height: 30px;
        border: #000000 1px solid;
    }

    table tr td input {
        border: none;
        width: 100%;
        height: 30px;
        outline: none;
        text-align: center;
    }

    table tr td textarea {
        border: none;
        width: 100%;
        height: 30px;
        outline: none;
        resize: none;

    }

    .tableTitle3Td {
        border: 1px solid #000;
        text-align: center;
        font-size: 12px;
        letter-spacing: 2px;
        line-height: 200%;
        padding: 0;
    }

    .changeCursorIco {
        cursor: pointer !important;
    }
</style>
<body class="hold-transition skin-yellow sidebar-mini">
<!--驳回模态框-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-reject">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">驳回</h4>
            </div>
            <div class="modal-body">
                <form id="rejectForm" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label for="rejectReasons" class="col-sm-12 control-label" style="text-align: left;padding-left: 22px;padding-top: 0px;">尊敬的用户，您确认要驳回此领料申请吗？</label>
                    </div>
                    <div class="form-group">
                        <label for="rejectReasons" class="col-sm-2 control-label no-padding-right">驳回原因</label>
                        <div class="col-sm-10">
                            <input name="id" type="hidden" style="display: none" />
                            <textarea name="rejectReasons" id="rejectReasons" class="form-control" cols="70" rows="8"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-reject-confirm">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box" style="box-shadow:none;border:none;">
                <div class="box-body">
                    <div class="col-md-12" style="padding-bottom: 25px;height: 50px;">
                        <button th:if="${verifySheet == null} and ${mode != 'view'} and ${mode != 'audit'}"
                                shiro:hasPermission="req:create:edit"
                                id="btn_save" class="btn btn-success pull-right"
                                style="margin-right: 100px;" onclick="save()"
                                type="button">保存
                        </button>
                        <button th:if="${verifySheet != null} and ${mode != 'view'} and ${mode != 'audit'}"
                                th:data="${verifySheet.id}"
                                shiro:hasPermission="req:create:edit"
                                id="btn_save"
                                class="btn btn-success pull-right"
                                style="margin-right: 100px;" onclick="save()"
                                type="button">保存
                        </button>
                        <button th:if="${verifySheet != null} and ${mode == 'audit'}" th:data="${verifySheet.id}"
                                shiro:hasPermission="req:audit:edit"
                                id="btn_reject"
                                class="btn btn-danger pull-right"
                                style="margin-right: 100px;" onclick="audit('reject')"
                                type="button">驳回
                        </button>
                        <button th:if="${verifySheet != null} and ${mode == 'audit'}" th:data="${verifySheet.id}"
                                shiro:hasPermission="req:audit:edit"
                                id="btn_pass"
                                class="btn btn-success pull-right"
                                style="margin-right: 20px;" onclick="audit('pass')"
                                type="button">通过
                        </button>
                        <a th:if="${mode == 'view'}" href="/materialRequisition/submitPage" type="button"
                           class="btn btn-success"
                           style="text-align:center;vertical-align:middle;font-size:30px;position:absolute;right:3%;display: inline-block;background-color: transparent;border: none;color: #5c5c5c;outline:none;">
                            <i style="-moz-transform:scaleX(-1);-webkit-transform:scaleX(-1);-o-transform:scaleX(-1);transform:scaleX(-1);filter:FlipH;"
                               class="glyphicon glyphicon-share-alt"></i><span
                                style="margin-left: 5px;font-size: 16px;position: absolute;top: 20%;">返回</span>
                        </a>
                        <a th:if="${mode == 'audit'}" href="/materialRequisition/auditPage" type="button"
                           class="btn btn-success"
                           style="text-align:center;vertical-align:middle;font-size:30px;position:absolute;right:3%;display: inline-block;background-color: transparent;border: none;color: #5c5c5c;outline:none;">
                            <i style="-moz-transform:scaleX(-1);-webkit-transform:scaleX(-1);-o-transform:scaleX(-1);transform:scaleX(-1);filter:FlipH;"
                               class="glyphicon glyphicon-share-alt"></i><span
                                style="margin-left: 5px;font-size: 16px;position: absolute;top: 20%;">返回</span>
                        </a>
                        <a th:if="${mode == 'viewQuery'}" href="/materialRequisition/queryPage" type="button"
                           class="btn btn-success"
                           style="text-align:center;vertical-align:middle;font-size:30px;position:absolute;right:3%;display: inline-block;background-color: transparent;border: none;color: #5c5c5c;outline:none;">
                            <i style="-moz-transform:scaleX(-1);-webkit-transform:scaleX(-1);-o-transform:scaleX(-1);transform:scaleX(-1);filter:FlipH;"
                               class="glyphicon glyphicon-share-alt"></i><span
                                style="margin-left: 5px;font-size: 16px;position: absolute;top: 20%;">返回</span>
                        </a>
                    </div>
                    <div class="col-xs-11 col-xs-offset-1">
                        <form id="dataForm">
                            <table id="formTable" width="100%" border="0" cellpadding="0" cellspacing="0"
                                   style="z-index: -2">
                                <tr id="tableTitle0">
                                    <td colspan="7">
                                        <img th:src="@{/img/logo3.jpg}" width="64px" height="40px"
                                             style="margin-top: -30px">
                                        <div style="display: inline-block;margin-top: 5px;margin-left: 20px">
                                            <span style="letter-spacing: 24px;display: block;line-height: 20px">&nbsp;辽宁忠旺机械设备制造有限公司</span>
                                            <span style="display: block;font-size: 12px;line-height: 20px">Liaoning Zhongwang Machinery Equipment Manufacturing Co., Ltd</span>
                                        </div>
                                    </td>
                                </tr>
                                <tr id="tableTitle1">
                                    <td colspan="7"
                                        style="font-size: 16px;letter-spacing: 4px;height: 35px">
                                        车间自用原材料领料申请单
                                    </td>
                                    <td style="border:none">
                                    </td>
                                </tr>
                                <tr id="tableTitle3">
                                    <td class="tableTitle3Td" width="60px">序号</td>
                                    <td class="tableTitle3Td" width="150px">物料用途</td>
                                    <td class="tableTitle3Td">物料名称</td>
                                    <td class="tableTitle3Td" width="80px">材质</td>
                                    <td class="tableTitle3Td" width="200px">规格</td>
                                    <td class="tableTitle3Td" width="80px">数量</td>
                                    <td class="tableTitle3Td" width="150px">备注</td>
                                    <td name="oper"
                                        style="border:0!important;width:60px;line-height: 200%;padding: 0;font-size: 12px;">
                                        <!--                                        <button th:if="${verifySheet == null}" id="btn_addRow" type="button"-->
                                        <!--                                                class="pull-left" onclick="addRow(this)"-->
                                        <!--                                                style="border:none;background:transparent;color:green;font-size: 18px">-->
                                        <!--                                            <i class="fa fa-plus"></i>-->
                                        <!--                                        </button>-->
                                    </td>
                                </tr>
                                <tr id="dataRow_1"
                                    th:if="${verifySheet == null}">
                                    <td class="tableTitle3Td">
                                        <input name="cmtdOrderNo" type="text"
                                               style="outline：none;cursor: pointer !important;" readOnly="readonly"
                                               value="1"/>
                                        <input name="cmtdId" type="hidden" style="display: none" readOnly="readonly"/>
                                    </td>
                                    <td class="tableTitle3Td">
                                        <input class="changeCursorIco" name="cmtdUse" type="text" style="outline：none;"
                                               maxlength="255"/>
                                    </td>
                                    <td class="tableTitle3Td">
                                        <input class="changeCursorIco" name="cmtdMatName" type="text"
                                               style="outline：none;" maxlength="255"/>
                                    </td>
                                    <td class="tableTitle3Td">
                                        <input class="changeCursorIco" name="cmtdTexture" type="text"
                                               style="outline：none;" maxlength="255"/>
                                    </td>
                                    <td class="tableTitle3Td">
                                        <input class="changeCursorIco" name="cmtdSpec" type="text" style="outline：none;"
                                               maxlength="255"/>
                                    </td>
                                    <td class="tableTitle3Td">
                                        <input class="changeCursorIco" name="cmtdNum" min="0.000001" max="210000000"
                                               type="text" oninput="formatNumber(this)" style="outline：none;"
                                               maxlength="255"/>
                                    </td>
                                    <td class="tableTitle3Td">
                                        <input class="changeCursorIco" name="cmtdRemark" type="text"
                                               style="outline：none;" maxlength="255"/>
                                    </td>
                                    <td th:if="${mode != 'view'} and ${mode != 'audit'}" name="oper"
                                        style="border:none;width:60px;line-height: 200%;padding: 0;font-size: 12px;">
                                        <button type="button" class="pull-left" onclick="addRow(this)"
                                                style="border:none;background:transparent;color:green;font-size: 12px">
                                            <i class="fa fa-plus"></i>
                                        </button>
                                    </td>
                                    <td th:if="${mode == 'view'} or ${mode == 'audit'}" name="oper"
                                        style="border:none;width:60px;line-height: 200%;padding: 0;font-size: 12px;"></td>
                                </tr>
                                <tr th:id="'dataRow_'+${item.cmtdOrderNo}"
                                    th:if="${verifySheet != null} and ${collMatDetailList.size() >0}"
                                    th:each="item,stat:${collMatDetailList}">
                                    <td class="tableTitle3Td" th:if="${stat.last==false} or ${stat.last==true}">
                                        <input name="cmtdOrderNo" type="text"
                                               style="outline：none;cursor: pointer !important;" readOnly="readonly"
                                               th:value="${item.cmtdOrderNo}"/>
                                        <input name="cmtdId" type="hidden"
                                               style="display: none" readOnly="readonly"
                                               th:value="${item.cmtdId}"/>
                                    </td>
                                    <td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdUse" type="text"
                                                                     style="outline：none;"
                                                                     maxlength="255" th:value="${item.cmtdUse}"/></td>
                                    <td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdMatName"
                                                                     type="text"
                                                                     style="outline：none;" maxlength="255"
                                                                     th:value="${item.cmtdMatName}"/>
                                    </td>
                                    <td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdTexture"
                                                                     type="text"
                                                                     style="outline：none;" maxlength="255"
                                                                     th:value="${item.cmtdTexture}"/>
                                    </td>
                                    <td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdSpec" type="text"
                                                                     style="outline：none;"
                                                                     maxlength="255" th:value="${item.cmtdSpec}"/></td>
                                    <td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdNum"
                                                                     min="0.000001" max="210000000"
                                                                     type="text" oninput="formatNumber(this)"
                                                                     style="outline：none;"
                                                                     maxlength="255" th:value="${item.cmtdNum}"/></td>
                                    <td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdRemark"
                                                                     type="text"
                                                                     style="outline：none;" maxlength="255"
                                                                     th:value="${item.cmtdRemark}"/>
                                    </td>
                                    <td style="border:none;width:60px;line-height: 200%;padding: 0;font-size: 12px;"
                                        th:if="${stat.last==false} and ${mode != 'view'} and ${mode != 'audit'} and ${mode != 'viewQuery'}"
                                        name="oper">
                                        <button type="button" class="pull-left"
                                                style="visibility: hidden">
                                            <i class="fa fa-plus"></i></button>
                                        <button type="button" class="pull-left" onclick="subtractRow(this)"
                                                style="border:none;background:transparent;color:red;font-size: 12px"><i
                                                class="fa fa-close"></i></button>
                                    </td>
                                    <td style="border:none;width:60px;line-height: 200%;padding: 0;font-size: 12px;"
                                        th:if="${stat.last==true} and ${mode != 'view'} and ${mode != 'audit'} and ${mode != 'viewQuery'}"
                                        name="oper">
                                        <button type="button" class="pull-left" onclick="addRow(this)"
                                                style="border:none;background:transparent;color:green;font-size: 12px">
                                            <i class="fa fa-plus"></i></button>
                                        <button type="button" class="pull-left" onclick="subtractRow(this)"
                                                style="border:none;background:transparent;color:red;font-size: 12px"><i
                                                class="fa fa-close"></i></button>
                                    </td>
                                    <td style="border:none;width:60px;line-height: 200%;padding: 0;font-size: 12px;"
                                        th:if="${mode == 'view'} or ${mode == 'audit'} or ${mode != 'viewQuery'}" name="oper"></td>
                                </tr>
                            </table>
                        </form>
                    </div>
                    <div class="col-xs-11 col-xs-offset-1" style="font-size: 16px;font-family:'Source Sans Pro','Helvetica Neue',Helvetica,Arial,sans-serif;line-height: 30px;padding-right: 80px;">
                        <div th:if="${verifySheet==null}" class="col-md-4 text-left">
                            <label class="control-label">
                                制单人：
                            </label>
                            <label th:text="${user.name}" class="control-label" style="margin-right: 15px;"></label>
                            <label th:text="${currentDate}" class="control-label"></label>
                        </div>
                        <div th:if="${verifySheet!=null}" class="col-md-4 text-left">
                            <label class="control-label">
                                制单人：
                            </label>
                            <label th:text="${verifySheet.makUserName}" class="control-label"
                                   style="margin-right: 15px;"></label>
                            <label th:text="${verifySheet.makCreateTime == null } ? '' : ${ #dates.format( verifySheet.makCreateTime, 'yyyy-MM-dd')}"
                                   class="control-label"></label>
                        </div>
                        <div th:if="${verifySheet!=null && verifySheet.revName !=null}" class="col-md-4 text-center">
                            <label class="control-label">
                                厂长签字：
                            </label>
                            <!--                                <img th:src="@{verifySheet.revSignUrl}"/>-->
                            <label th:text="${verifySheet.revName == null } ? '' : ${verifySheet.revName }"
                                   class="control-label"></label>
                            <label th:text="${verifySheet.revTime == null } ? '' : ${ #dates.format( verifySheet.revTime, 'yyyy-MM-dd')}"
                                   class="control-label"></label>
                        </div>
                        <div th:if="${verifySheet!=null && verifySheet.appName !=null}" class="col-md-4 text-right">
                            <label class="control-label">
                                副总签字：
                            </label>
                            <!--                                <img th:src="@{verifySheet.appSignUrl}"/>-->
                            <label th:text="${verifySheet.appName == null } ? '' : ${verifySheet.appName }"
                                   class="control-label"></label>
                            <label th:text="${verifySheet.appTime == null } ? '' : ${ #dates.format( verifySheet.appTime, 'yyyy-MM-dd')}"
                                   class="control-label"></label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let delCmtdIdArray = new Array();

    /**
     * Jquery 就绪函数
     */
    $(function () {
        $("#btn-reject-confirm").click(function (){
            js.post({
                url: ctx + "materialRequisition/audit",
                data: {
                    id: $("#rejectForm [name='id']").val(),
                    rejectReasons: $("#rejectForm [name='rejectReasons']").val(),
                    type: 'reject'
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    location.href = "/materialRequisition/auditPage";
                }
            });
        });
    });

    /**
     * 添加新行
     */
    function addRow(obj) {
        let tdEl = new Array();
        let newOrderNo = getNewOrderNo();
        tdEl.push('<td class="tableTitle3Td"><input name="cmtdOrderNo" type="text" style="outline：none;cursor: pointer !important;" readOnly="readonly" value="' + newOrderNo + '"/><input name="cmtdId" type="hidden" style="display: none" readOnly="readonly"/></td>');
        tdEl.push('<td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdUse" type="text" style="outline：none;" maxlength="255" /></td>');
        tdEl.push('<td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdMatName" type="text" style="outline：none;" maxlength="255"/></td>');
        tdEl.push('<td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdTexture" type="text" style="outline：none;" maxlength="255"/></td>');
        tdEl.push('<td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdSpec" type="text" style="outline：none;" maxlength="255"/></td>');
        tdEl.push('<td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdNum" min="0.000001" max="210000000" type="text" oninput="formatNumber(this)" style="outline：none;" maxlength="255"/></td>');
        tdEl.push('<td class="tableTitle3Td"><input class="changeCursorIco" name="cmtdRemark" type="text" style="outline：none;" maxlength="255"/></td>');
        tdEl.push('<td name="oper" style="border:none;width:60px;line-height: 200%;padding: 0;font-size: 12px;"><button type="button" class="pull-left" onclick="addRow(this)" style="border:none;background:transparent;color:green;font-size: 12px"><i class="fa fa-plus"></i></button><button type="button" class="pull-left" onclick="subtractRow(this)" style="border:none;background:transparent;color:red;font-size: 12px"> <i class="fa fa-close"></i></button></td>');
        $(obj).parent().parent().after('<tr id="dataRow_' + newOrderNo + '">' + tdEl + '</tr>')
        $(obj).parent().html('');
    }

    /**
     * 移除本行
     */
    function subtractRow(obj) {
        if ($(obj).parent().parent().find("[name='cmtdId']").val() != null && $(obj).parent().parent().find("[name='cmtdId']").val() != '') {
            delCmtdIdArray.push($(obj).parent().parent().find("[name='cmtdId']").val());
        }
        $(obj).parent().parent().remove();
        let lastId = $('#formTable tr:last').attr('id');
        if (lastId === 'dataRow_1') {
            $('#formTable tr:last').find("[name='oper']").html('<button type="button" class="pull-left" onclick="addRow(this)" style="border:none;background:transparent;color:green;font-size: 12px"><i class="fa fa-plus"></i></button>');
        } else {
            $('#formTable tr:last').find("[name='oper']").html('<button type="button" class="pull-left" onclick="addRow(this)" style="border:none;background:transparent;color:green;font-size: 12px"><i class="fa fa-plus"></i></button><button type="button" class="pull-left" onclick="subtractRow(this)" style="border:none;background:transparent;color:red;font-size: 12px"> <i class="fa fa-close"></i></button>');
        }
        //重新排序
        let index = 1;
        $("#formTable tr [name='orderNo']").each(function () {
            $(this).html(index);
            index++;
        });
    }

    /**
     * 获取最新行号
     */
    function getNewOrderNo() {
        let rowIndex = 1;
        $("#formTable tr").each(function () {
            let idText = $(this).attr("id");
            if (idText.indexOf("dataRow") > -1) {
                rowIndex++;
            }
        });
        return rowIndex;
    }

    /**
     * 验证输入有效的整数和四位小数
     */
    function formatNumber(obj) {
        obj.value = obj.value.replace(/[^-\d.]/g, "");  //清除“数字”和“.”以外的字符
        obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
        obj.value = obj.value.replace(/\-{2,}-/g, "-"); //只保留第一个. 清除多余的
        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d\d\d\d\d).*$/, '$1$2.$3');//只能输入六个小数
        if (obj.value.indexOf(".") < 0 && obj.value != "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
            obj.value = obj.value;
        }
        //如果上去就写- 自动替换
        if (obj.value.indexOf("-") >= 0) {
            obj.value = obj.value.replace('-', "");
        }
        if (obj.value == '00') {
            obj.value = obj.value = '0';
        }
        //如果上去就写.   自动补个0   形成0.
        if (obj.value.indexOf(".") == 0) {
            obj.value = "0" + obj.value;
        } else if (obj.value.indexOf(".") > 1) {
            //如果输入01.3自动变成1.3，自动去除整数部分的0
            if (obj.value.indexOf("0") == 0) {
                obj.value = obj.value.substr(1, obj.value.length - 1);
            }
        }
        //如果输入023直接变成23;自动去除整数部分的0
        if (obj.value.length > 2 && obj.value.indexOf(".") < 0) {
            if (obj.value.indexOf("0") == 0) {
                obj.value = obj.value.substr(1, obj.value.length - 1);
            }
        }
        if (obj.value.indexOf(".") > 0 && obj.value.substring(obj.value.indexOf(".") + 1).length === 6 && obj.value != '0.000000') {
            js.modal.warning('最多输入6位小数。');
        }
        if (obj.value.indexOf(".") > 0 && obj.value.substring(obj.value.indexOf(".") + 1).length === 6 && obj.value === '0.000000') {
            obj.value = '0.00000';
            js.modal.warning('最多输入6位小数,且最后一位不可输入0。');
        }
    }

    /**
     * 保存
     */
    function save() {
        let dataArray = new Array();
        let dataModel = new Object();
        let cmtdUseIWarningInfo = '';
        let cmtdUseIndex = 1;
        let cmtdMatNameWarningInfo = '';
        let cmtdMatNameIndex = 1;
        let cmtdTextureWarningInfo = '';
        let cmtdTextureIndex = 1;
        let cmtdSpecWarningInfo = '';
        let cmtdSpecIndex = 1;
        let cmtdNumWarningInfo = '';
        let cmtdNumIndex = 1;
        $.each($("#dataForm").serializeArray(), function (_, kv) {
            if (kv.name === 'cmtdUse') {
                if (kv.value === '') {
                    cmtdUseIWarningInfo += "第" + cmtdUseIndex + "行、";
                    cmtdUseIndex++
                }
            }
            if (kv.name === 'cmtdMatName') {
                if (kv.value === "") {
                    cmtdMatNameWarningInfo += "第" + cmtdMatNameIndex + "行、";
                    cmtdMatNameIndex++;
                }
            }
            if (kv.name === 'cmtdTexture') {
                if (kv.value === "") {
                    cmtdTextureWarningInfo += "第" + cmtdTextureIndex + "行、";
                    cmtdTextureIndex++;
                }
            }
            if (kv.name === 'cmtdSpec') {
                if (kv.value === "") {
                    cmtdSpecWarningInfo += "第" + cmtdSpecIndex + "行、";
                    cmtdSpecIndex++;
                }
            }
            if (kv.name === 'cmtdNum') {
                if (kv.value === "") {
                    cmtdNumWarningInfo += "第" + cmtdNumIndex + "行、";
                    cmtdNumIndex++;
                }
            }
        });
        if (cmtdUseIWarningInfo.length > 0 || cmtdMatNameWarningInfo.length > 0 || cmtdTextureWarningInfo.length > 0) {
            // if (cmtdUseIWarningInfo.length > 0) {
            //     cmtdUseIWarningInfo = cmtdUseIWarningInfo.substring(0, cmtdUseIWarningInfo.length - 1);
            //     js.modal.warning("尊敬的用户，请填写" + cmtdUseIWarningInfo + "物料用途！");
            //     return false;
            // }
            if (cmtdMatNameWarningInfo.length > 0) {
                cmtdMatNameWarningInfo = cmtdMatNameWarningInfo.substring(0, cmtdMatNameWarningInfo.length - 1);
                js.modal.warning("尊敬的用户，请填写" + cmtdMatNameWarningInfo + "物料名称！");
                return false;
            }
            // if (cmtdTextureWarningInfo.length > 0) {
            //     cmtdTextureWarningInfo = cmtdTextureWarningInfo.substring(0, cmtdTextureWarningInfo.length - 1);
            //     js.modal.warning("尊敬的用户，请填写" + cmtdTextureWarningInfo + "材质！");
            //     return false;
            // }
            // if (cmtdSpecWarningInfo.length > 0) {
            //     cmtdSpecWarningInfo = cmtdSpecWarningInfo.substring(0, cmtdSpecWarningInfo.length - 1);
            //     js.modal.warning("尊敬的用户，请填写" + cmtdSpecWarningInfo + "规格！");
            //     return false;
            // }
            if (cmtdNumWarningInfo.length > 0) {
                cmtdNumWarningInfo = cmtdNumWarningInfo.substring(0, cmtdNumWarningInfo.length - 1);
                js.modal.warning("尊敬的用户，请填写" + cmtdNumWarningInfo + "数量！");
                return false;
            }
            return;
        }
        $.each($("#dataForm").serializeArray(), function (_, kv) {
            if (kv.name === 'cmtdId') {
                if (kv.value != "") {
                    dataModel.cmtdId = kv.value;
                } else {
                    dataModel.cmtdId = null;
                }
            }
            if (kv.name === 'cmtdOrderNo') {
                dataModel.cmtdOrderNo = kv.value;
            }
            if (kv.name === 'cmtdUse') {
                dataModel.cmtdUse = kv.value;
            }
            if (kv.name === 'cmtdMatName') {
                dataModel.cmtdMatName = kv.value;
            }
            if (kv.name === 'cmtdTexture') {
                dataModel.cmtdTexture = kv.value;
            }
            if (kv.name === 'cmtdSpec') {
                dataModel.cmtdSpec = kv.value;
            }
            if (kv.name === 'cmtdNum') {
                dataModel.cmtdNum = kv.value;
            }
            if (kv.name === 'cmtdRemark') {
                if (kv.value != "") {
                    dataModel.cmtdRemark = kv.value;
                } else {
                    dataModel.cmtdRemark = null;
                }
                if (dataModel.cmtdMatName != undefined) {
                    dataArray.push(dataModel);
                    dataModel = new Object();
                }

            }

        });
        if (dataArray.length > 0) {
            js.post({
                url: ctx + 'materialRequisition/save',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {
                    sheetId: $("#btn_save").attr('data'),
                    collMatDetailJson: JSON.stringify(dataArray),
                    delCmtdIdArrayJson: JSON.stringify(delCmtdIdArray)
                },
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        location.href = ctx + "materialRequisition/submitPage";
                    } else {
                        js.modal.warning(result.msg);
                    }
                },
                error: function () {
                    js.modal.fail();
                }
            });
        } else {
            js.modal.warning("尊敬的用户，请录入车间自用原材料领料申请单！");
            return;
        }
    }

    /**
     * @methodName: audit
     * @description: 审核
     * @param: oper
     * @return：
     * @exception：
     * @author： 徐一贺 tel:18341916590
     * @designer： 陈欣，盖世奇
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/4/13 13:56
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    function audit(oper) {
        if (oper === 'pass') {
            js.confirmPost({
                content: "尊敬的用户，您确认要通过此领料申请吗？",
                url: ctx + "materialRequisition/audit",
                data: {
                    id: $("#btn_pass").attr('data'),
                    rejectReasons: $("#rejectForm [name='rejectReasons']").val(),
                    type: 'pass'
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    location.href = "/materialRequisition/auditPage";
                }
            });
        } else if (oper === 'reject') {
            $("#rejectForm [name='id']").val($("#btn_reject").attr('data'));
            js.modal.open('modal-reject');
            // js.confirmPost({
            //     content: "尊敬的用户，您确认要驳回此领料申请吗？",
            //     url: ctx + "materialRequisition/audit",
            //     data: {
            //         id: $("#btn_reject").attr('data'),
            //         type: 'reject'
            //     },
            //     success: function (result) {
            //         if (result.type === web_status.SUCCESS) {
            //             js.modal.success(result.msg);
            //         } else {
            //             js.modal.warning(result.msg);
            //         }
            //         location.href = "/materialRequisition/auditPage";
            //     }
            // });
        }
    }
</script>
</body>
</html>